<template>
  <a-card :bordered="false">

    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="12">

          <a-col :md="4" :sm="8">
            <a-form-item label="车牌号">
              <a-input placeholder="请输入车牌号" v-model="queryParam.plateNo"></a-input>
            </a-form-item>
          </a-col>

          <a-col :md="4" :sm="8">
            <a-form-item label="出口名称">
              <a-select :options="armNameOptions" v-model="queryParam.armName" placeholder="请选择出口名称"></a-select>
            </a-form-item>
          </a-col>

          <a-col :md="4" :sm="8">
            <a-form-item label="开闸类型">
                <a-select v-model="queryParam.swichType" placeholder="请选择开闸类型">
                  <a-select-option :value="''">请选择开闸类型</a-select-option>
                  <a-select-option :value="0">场端开闸</a-select-option>
                  <a-select-option :value="1">自动开闸</a-select-option>
                  <a-select-option :value="2">手持端开闸</a-select-option>
                  <a-select-option :value="3">云端开闸</a-select-option>
                </a-select>
              </a-form-item>
          </a-col>

          <a-col :md="4" :sm="8">
            <a-form-item label="开始日期">
              <a-date-picker placeholder="开始日期" @change="onChangeStartTime"/>
            </a-form-item>
          </a-col>
          <a-col :md="4" :sm="8">
            <a-form-item label="结束日期">
              <a-date-picker placeholder="结束日期" @change="onChangeEndTime"/>
            </a-form-item>
          </a-col>

          <a-col :md="4" :sm="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>

    <!-- table区域-begin -->
    <div>
    

      <a-table
          ref="table"
          size="middle"
          bordered
          rowKey="id"
          :columns="columns"
          :dataSource="dataSource"
          :pagination="ipagination"
          :loading="loading"
          @change="handleTableChange">

         <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">详情</a>
        </span>

      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <sdkOpenGateLog-modal ref="modalForm" @ok="modalFormOk"></sdkOpenGateLog-modal>
  </a-card>
</template>

<script>
import SdkOpenGateLogModal from './modules/SdkOpenGateLogModal'
import {JeecgListMixin} from '@/mixins/JeecgListMixin'
import {getAction} from '@/api/manage'
import {filterObj} from '@/utils/util';
import JEllipsis from '@/components/jeecg/JEllipsis'


export default {
  name: "SdkOpenGateLogList",
  mixins: [JeecgListMixin],
  components: {
    SdkOpenGateLogModal,
    JEllipsis
  },
  data() {
    // let ellipsis = (v, l = 10) => (<j-ellipsis value={v} length={l}/>)
    return {
      description: '开闸日志管理页面',
      
      // 表头
      columns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 50,
          align: "center",
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '停车场名称',
          align: "center",
          dataIndex: 'parkName'
        },
        {
          title: '出口名称',
          align: "center",
          dataIndex: 'armName'
        },
        {
          title: '设备序列号',
          align: "center",
          dataIndex: 'serialNo'
        },
        {
          title: '车牌号',
          align: "center",
          dataIndex: 'plateNo'
        },
        // {
        //   title: 'IP',
        //   align: "center",
        //   dataIndex: 'ipAddr'
        // },
        {
          title: '开闸类型',
          align: "center",
          dataIndex: 'swichType',
          customRender:function(t,r,index){
            switch(t){
              case '0' : t="场端开闸"
                break
              case '1' : t="自动开闸"
                break
              case '2' : t="手持端开闸"
                break
              case '3' : t="云端开闸"
                break
            }
            return t
          }
        //   customRender: (t) => ellipsis(t),
        },
        {
          title: '开闸放行备注',
          align: "center",
          dataIndex: 'remark'
        },
        {
          title: '创建时间',
          align: "center",
          dataIndex: 'createTime'
        },
        {
          title: '操作',
          dataIndex: 'action',
          scopedSlots: {customRender: 'action'},
          align: 'center'
        }
      ],
      url: {
        list: "/sdkopengatelog/sdkOpenGateLog/list",
        delete: "/sdkopengatelog/sdkOpenGateLog/delete",
        deleteBatch: "/sdkopengatelog/sdkOpenGateLog/deleteBatch",
        armNameList:"/parking/parkArmInfo/getParkArmList"
        // exportXlsUrl: "SdkOpenGateLog/SdkOpenGateLog/exportXls",
        // importExcelUrl: "SdkOpenGateLog/SdkOpenGateLog/importExcel",
      },
      queryParam: {
        createTime_begin:'',
        createTime_end:''
        
      },
      isorter: {
        column: 'createTime',
        order: 'desc',
      },
    }
  },

  created() {
    this.keyupEnter(),
    this.loadArmNameData()
  },
  methods: {
      handleEdit: function (record) {
      this.$refs.modalForm.edit(record);
      this.$refs.modalForm.title = "详情";
      this.$refs.modalForm.disableSubmit = false;
    },
    onChangeStartTime(date, dateString) {
      this.queryParam.createTime_begin = dateString
    },

    onChangeEndTime(date, dateString) {
      this.queryParam.createTime_end = dateString
    },

    loadData(arg) {
      if (!this.url.list) {
        this.$message.error('请设置url.list属性!')
        return
      }
      if (arg === 1) {
        this.ipagination.current = 1
      }
      var params = this.getQueryParams()
      this.loading = true
      getAction(this.url.list, params).then(res => {
        if (res.success) {
          this.dataSource = res.result.records
          this.ipagination.total = res.result.total
        }
        if (res.code === 510) {
          this.$message.warning(res.message)
        }
        this.loading = false
      })
    },

    searchQuery() {
      let startTime = this.queryParam.createTime_begin
      let endTime = this.queryParam.createTime_end

      if (startTime != "" && endTime != "") {
        if (startTime > endTime) {
          this.$message.error('开始时间不能大于结束时间')
          return
        }
      }

      if (startTime == "" && endTime != "") {
        this.$message.error('请选择开始时间')
        return
      }

      if (startTime != "" && endTime == "") {
        this.$message.error('请选择结束时间')
        return
      }

      this.loadData(1)
    },

    getQueryParams() {
      var param = Object.assign({}, this.isorter, this.queryParam)
      param.field = this.getQueryField()
      param.pageNo = this.ipagination.current
      param.pageSize = this.ipagination.pageSize
      if (this.queryParam.createTime_begin != "" && this.queryParam.createTime_end != "") {
        param.createTime_begin = this.queryParam.createTime_begin + ' 00:00:00'
        param.createTime_end = this.queryParam.createTime_end + ' 23:59:59'
      }
      return filterObj(param)
    },

    keyupEnter() {
      document.onkeydown = e => {
        let body = document.getElementsByTagName('body')[0]
        if (e.keyCode === 13) {
          this.loadData(1)
        }
      }
    },

    loadArmNameData() {
      getAction(this.url.armNameList).then(res=>{
        if(res.result)
        {
           this.armNameOptions = [{value:'',label:'请选择出口名称'}]
           res.result.forEach(pageList=>{
             this.armNameOptions.push({
               key:pageList.armName,
               label:pageList.armName,
               value:pageList.armName
             })
           })
        }else {
          this.$message.error(res.message)
        }
      })
    },
  }


}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>